package main

import (
	"fmt"
	"time"
)

func counter(numChan chan<- int) {
	for i := 1; i < 200001; i++ {
		numChan <- i
	}
	close(numChan)
}
func Fx(resChan chan map[int]int, numChan <-chan int, ex chan bool) {

	for c := range numChan {
		res := make(map[int]int)
		var sum int
		for i := 1; i <= c; i++ {
			sum = sum + i
		}
		res[c] = sum
		resChan <- res
	}
	ex <- true

}
func main() {

	numChan := make(chan int, 200000)
	resChan := make(chan map[int]int, 200000)
	flag := make(chan bool, 4)
	start := time.Now().Unix()

	go counter(numChan)

	for i := 0; i < 4; i++ {
		go Fx(resChan, numChan, flag)
	}

	go func() {

		for i := 0; i < 4; i++ {
			<-flag
		}
		close(resChan)
		end := time.Now().Unix()
		fmt.Println(end - start)

	}()

	for {
		_, ok := <-resChan
		if !ok {
			break
		}
	}
}
